package com.example.lenovo.widget106;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv;
    private EditText et;
    private Button buttontext,buttonimg;
    private ImageButton imb;
    private ImageView imv;

    private RadioGroup rg;
    private RadioButton rbnan,rbnv;
    private Button buttonder,buttonfun;
    private CheckBox cbzuo,cbzhong,cbyou;
private String strfun="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        tv=(TextView)findViewById(R.id.textView);
        et=(EditText) findViewById(R.id.editText);
        buttontext=(Button)findViewById(R.id.button3);
        buttonimg=(Button)findViewById(R.id.button4);
        imb=(ImageButton)findViewById(R.id.imageButton);
        imv=(ImageView)findViewById(R.id.imageView3);

        rbnan=(RadioButton)findViewById(R.id.radioButton);
        rbnv=(RadioButton)findViewById(R.id.radioButton2) ;
        rg=(RadioGroup)findViewById(R.id.radiogroup);
        buttonder=(Button)findViewById(R.id.button2);
        buttonfun=(Button)findViewById(R.id.button5) ;
        cbzuo=(CheckBox)findViewById(R.id.checkBox9);
        cbzhong=(CheckBox)findViewById(R.id.checkBox8);
        cbyou=(CheckBox)findViewById(R.id.checkBox7);
        buttontext.setOnClickListener(this);
        buttonimg.setOnClickListener(this);
        imb.setOnClickListener(this);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                case R.id.radioButton:
                tv.setText("男");
                break;
                case R.id.radioButton2:
                tv.setText("女");
                    break;
                 }}
            }
            );
        cbzuo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="篮球+";
                else
                    strfun=strfun.replace("篮球+","");
                tv.setText(strfun);
            }
        });
        cbzhong.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="足球+";
                else
                    strfun=strfun.replace("足球+","");
                tv.setText(strfun);
            }
        });
        cbyou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                    strfun+="游泳+";
                else
                    strfun=strfun.replace("游泳+","");
                tv.setText(strfun);
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button2:
                if(rbnan.isChecked())
                    tv.setText("男");
                if(rbnv.isChecked())
                    tv.setText("女");
            case R.id.button3:
                String str=et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button4:
                imv.setImageResource(R.drawable.aa);
                break;
            case R.id.button5:
                String msg="";
                if(cbzuo.isChecked()) msg+="篮球+";
                if(cbzhong.isChecked()) msg+="足球+";
                if(cbyou.isChecked()) msg+="游泳+";
                tv.setText(msg);


            case R.id.imageButton:
                Intent intent=new Intent(MainActivity.this,NewActivity.class);
                intent.putExtra("param1",et.getText().toString());
                intent.putExtra("param2",3);
                startActivity(intent);//跳转新窗口
                break;
        }
    }
}
